/*
 * CommandLineParser.cpp
 *
 *  Created on:  May 29, 2009
 *      Author:  Zach Riggle A37627537
 *      Project: CSE410 Project 1
 */

#include "CommandLineParser.h"
#include "Log.h"

const string CommandLineParser::parallel = "-p";
const string CommandLineParser::threaded = "-t";

const int CommandLineParser::inputOffset = 1;
const int CommandLineParser::outputOffset = 2;
const int CommandLineParser::optionOffset = 3;

CommandLineParser::CommandLineParser(int argc, char** argv) {
    doParallel = doThreaded = false;
    valid = false;

    if (argc < outputOffset) {
        switch (argc) {
        case inputOffset:
            error("Must provide an input file as argument number "
                  << inputOffset);
        case outputOffset:
            error("Must provide an output file as argument number "
                  << outputOffset);
        }
        return;
    }

    inputFile = argv[inputOffset];
    info("Using input file " << inputFile);
    outputFile = argv[outputOffset];
    info("Using output file " << outputFile);

    if (argc > optionOffset) {
        if (parallel.compare(argv[optionOffset]) == 0) {
            doParallel = true;
            info("Set parallel mode");
        }

        else if (threaded.compare(argv[optionOffset]) == 0) {
            doThreaded = true;
            info("Set threaded mode");
        }

        else
            info("Set single-process mode");
    }

    valid = true;
}

CommandLineParser::~CommandLineParser() {
}

bool CommandLineParser::isParallel() {
    return doParallel;
}

bool CommandLineParser::isThreaded() {
    return doThreaded;
}

string CommandLineParser::getInputFile() {
    return inputFile;
}

string CommandLineParser::getOutputFile() {
    return outputFile;
}

bool CommandLineParser::isValid() {
    return valid;
}
